package com.qianqu.module_finding.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;

import com.qianqu.lib_base.utils.AnimUtil;
import com.qianqu.lib_base.utils.FragmentUtils;
import com.qianqu.module_finding.R;
import com.qianqu.module_finding.adapter.MainAdapter;
import com.qianqu.module_finding.adapter.TabAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * ${description}
 *
 * @author weiqiliu
 * @version 1.0 2018/6/25
 */
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private ViewPager viewPager;
    private MainAdapter mainAdapter;
    private RecyclerView recyclerView,recyclerView2;
    private ArrayList<Fragment> fragmentList = new ArrayList<>();
    private TabAdapter adapter,adapter2;
    private LinearLayout morningLayout, afternoonLayout;
    private View lineMorning, lineAfternoon;
    private List<String> timeMorninglist=new ArrayList<>();
    private List<String> timeAfternoonlist=new ArrayList<>();
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
        setViewPagerAdapter();
    }

    private void initView() {
        viewPager = (ViewPager) findViewById(R.id.viewPager);
        recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
        recyclerView2 = (RecyclerView) findViewById(R.id.recyclerview_2);
        morningLayout = (LinearLayout) findViewById(R.id.morning_layout);
        afternoonLayout = (LinearLayout) findViewById(R.id.afternoon_layout);
        lineMorning = (View) findViewById(R.id.line1);
        lineAfternoon = (View) findViewById(R.id.line2);
        morningLayout.setOnClickListener(this);
        afternoonLayout.setOnClickListener(this);
        recyclerView2.setAlpha((float) 0.0);
        lineAfternoon.setAlpha((float) 0.0);

        //Recyclerview
        timeMorninglist.add("1111");
        timeMorninglist.add("1111");
        timeMorninglist.add("1111");
        timeMorninglist.add("1111");
        adapter = new TabAdapter(MainActivity.this,timeMorninglist);
        GridLayoutManager gridLayoutManager = new GridLayoutManager(MainActivity.this, 3);
        recyclerView.setLayoutManager(gridLayoutManager);
        //滑动不卡
        recyclerView.setHasFixedSize(true);
        recyclerView.setNestedScrollingEnabled(false);
        recyclerView.setAdapter(adapter);

        timeAfternoonlist.add("dfggg");
        timeAfternoonlist.add("dfggg");
        timeAfternoonlist.add("dfggg");
        timeAfternoonlist.add("dfggg");
        timeAfternoonlist.add("dfggg");
        adapter2 = new TabAdapter(MainActivity.this,timeAfternoonlist);
        GridLayoutManager gridLayoutManager2 = new GridLayoutManager(MainActivity.this, 3);
        recyclerView2.setLayoutManager(gridLayoutManager2);
        //滑动不卡
        recyclerView2.setHasFixedSize(true);
        recyclerView2.setNestedScrollingEnabled(false);
        recyclerView2.setAdapter(adapter2);
    }

    private void initData() {
        fragmentList.clear();
        fragmentList.add(FragmentUtils.getFindingFragment());
    }

    private void setViewPagerAdapter() {
        mainAdapter = new MainAdapter(getSupportFragmentManager(), fragmentList);
        viewPager.setAdapter(mainAdapter);
    }

    @Override
    public void onClick(View v) {

    }
}
